<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: banner_statistics.php 19 2013-09-21 11:53:03Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 19 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:53:03 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */


  require('includes/application_top.php');

  $banner_extension = banner_image_extension();

  // check if the graphs directory exists
  $dir_ok = false;
  if ( (function_exists('imagecreate')) && ($banner_extension) ) {
    if (is_dir(DIR_WS_IMAGES . 'graphs')) {
      if (is_writeable(DIR_WS_IMAGES . 'graphs')) {
        $dir_ok = true;
      } else {
        $message_stack->add(ERROR_GRAPHS_DIRECTORY_NOT_WRITEABLE, 'error');
      }
    } else {
      $message_stack->add(ERROR_GRAPHS_DIRECTORY_DOES_NOT_EXIST, 'error');
    }
  }

  $banner = $db->db_query("SELECT banners_title from " . TABLE_BANNERS . " WHERE banners_id = '" . $_GET['bID'] . "'");

  $years_array = array();
  $years = $db->db_query("SELECT distinct year(banners_history_date) as banner_year from " . TABLE_BANNERS_HISTORY . " WHERE banners_id = '" . $_GET['bID'] . "'");
  while(!$years->EOF) {
    $years_array[] = array('id' => $years->fields['banner_year'],'text' => $years->fields['banner_year']);
    $years->MoveNext();
  }

  $months_array = array();
  for ($i=1; $i<13; $i++) {
    $months_array[] = array('id' => $i,
                            'text' => strftime('%B', mktime(0,0,0,$i)));
  }

  $type_array = array(array('id' => 'daily',
                            'text' => STATISTICS_TYPE_DAILY),
                      array('id' => 'monthly',
                            'text' => STATISTICS_TYPE_MONTHLY),
                      array('id' => 'yearly',
                            'text' => STATISTICS_TYPE_YEARLY));
require(DIR_WS_INCLUDES . 'metatag.php'); ?>
</head>
<body>
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellspacing="0" cellpadding="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
			<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
    	</table>
	</td>
    <td class="boxCenter" valign="top">
	 <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%">
			<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
	   			 <tr>
	     		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
			  </tr>
			</table>
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="main" align="right"><?php echo draw_form('year', FILENAME_BANNER_STATISTICS, '', 'get'); ?>
				<?php echo TITLE_TYPE . ' ' . draw_pull_down_menu('type', $type_array, (($_GET['type']) ? $_GET['type'] : 'daily'), 'onChange="this.form.submit();"'); ?>
				<noscript><input type="submit" value="GO"></noscript><br />
			<?php
			  switch ($_GET['type']) {
			    case 'yearly': break;
			    case 'monthly':
			      echo TITLE_YEAR . ' ' . draw_pull_down_menu('year', $years_array, (($_GET['year']) ? $_GET['year'] : date('Y')), 'onChange="this.form.submit();"') . '<noscript><input type="submit" value="GO"></noscript>';
			      break;
			    default:
			    case 'daily':
			      echo TITLE_MONTH . ' ' . draw_pull_down_menu('month', $months_array, (($_GET['month']) ? $_GET['month'] : date('n')), 'onChange="this.form.submit();"') . '<noscript><input type="submit" value="GO"></noscript><br />' . TITLE_YEAR . ' ' . draw_pull_down_menu('year', $years_array, (($_GET['year']) ? $_GET['year'] : date('Y')), 'onChange="this.form.submit();"') . '<noscript><input type="submit" value="GO"></noscript>';
			      break;
			  }
			?>
            </td>
          <?php echo draw_hidden_field('page', $_GET['page']) . draw_hidden_field('bID', $_GET['bID']);
          echo '</form>';
          ?></tr>
        </table></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="center">
			<?php
			  if ( (function_exists('imagecreate')) && ($dir_ok) && ($banner_extension) ) {
			    $banner_id = $_GET['bID'];
			    switch ($_GET['type']) {
			      case 'yearly':
			        include(DIR_WS_INCLUDES . 'graphs/banner_yearly.php');
			        echo image(DIR_WS_IMAGES . 'graphs/banner_yearly-' . $banner_id . '.' . $banner_extension);
			        break;
			      case 'monthly':
			        include(DIR_WS_INCLUDES . 'graphs/banner_monthly.php');
			        echo image(DIR_WS_IMAGES . 'graphs/banner_monthly-' . $banner_id . '.' . $banner_extension);
			        break;
			      default:
			      case 'daily':
			        include(DIR_WS_INCLUDES . 'graphs/banner_daily.php');
			        echo image(DIR_WS_IMAGES . 'graphs/banner_daily-' . $banner_id . '.' . $banner_extension);
			        break;
			    }
			?>
          <table class="dataTable">
            <tr class="dataTableHeadingRow">
             <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_SOURCE; ?></td>
             <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_VIEWS; ?></td>
             <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_CLICKS; ?></td>
           </tr>
			<?php
			    for ($i = 0, $n = sizeof($stats); $i < $n; $i++) {
			      echo '            <tr class="dataTableRow">' . "\n" .
			           '              <td class="dataTableContent">' . $stats[$i][0] . '</td>' . "\n" .
			           '              <td class="dataTableContent" align="right">' . number_format($stats[$i][1]) . '</td>' . "\n" .
			           '              <td class="dataTableContent" align="right">' . number_format($stats[$i][2]) . '</td>' . "\n" .
			           '            </tr>' . "\n";
			    }
			?>
          </table>
		<?php
		  } else {
		    include(DIR_WS_FUNCTIONS . 'html_graphs.php');
		    switch ($_GET['type']) {
		      case 'yearly':
		        echo banner_graph_yearly($_GET['bID']);
		        break;
		      case 'monthly':
		        echo banner_graph_monthly($_GET['bID']);
		        break;
		      default:
		      case 'daily':
		        echo banner_graph_daily($_GET['bID']);
		        break;
		    }
		  }
		?>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td class="main" align="right"><?php echo '<a class="button" onClick="this.blur();" href="' . href_link(FILENAME_BANNER_MANAGER, 'page=' . $_GET['page'] . '&bID=' . $_GET['bID']) . '">' . BUTTON_BACK . '</a>'; ?></td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>